package com.i5.distributedlock.core.key.strategy;

import com.i5.distributedlock.core.key.LockKey.Builder;
import com.i5.distributedlock.core.key.RedisLockKey;
import com.i5.distributedlock.core.key.ZookeeperLockKey;
import com.i5.distributedlock.enumeration.LockScheme;
import com.i5.distributedlock.exception.KeyBuilderException;

import java.lang.reflect.Method;

public class ClassKeyStrategy extends KeyStrategy {

    public ClassKeyStrategy(LockScheme scheme, String className, String methodName, Method realMethod, Object[] args, String prefixName) {
        super(scheme, className, methodName, realMethod, args, prefixName);
    }

    @Override
    public Builder generateBuilder() throws KeyBuilderException {
        Builder keyBuilder;
        if (scheme == LockScheme.REDIS) {
            keyBuilder = RedisLockKey.newRedisKeyBuilder();
        } else {
            keyBuilder = ZookeeperLockKey.newZookeeperKeyBuilder();
        }
        keyBuilder.appendKey(wrapKeyTag(new StringBuilder(getSimpleClassName()).append(".").append(methodName).toString()));

        return keyBuilder;
    }

}
